var schoolList;
var schArea;
var schCity;
var searchSch;
var key;
var strDom;
$(document).ready(function () {
    schoolList = $('#SchoolList');
    searchSch  = $('#bt_SchoolList_Search');
    strDom     = $('#SchoolList_Search');
    schArea    = '';
    schCity    = '';
    $('.xh-datagrid-toolbar').parseToolbar();
    schoolList.initDataGrid(baseUrl + 'tch/getSch');

    DataGrid.onLoadSuccess = function(data){ //默认选择第一行
        if(data['rows'].length <= 0) return false;
        schoolList.datagrid('selectRow',0);
        setUrl(data['rows'][0]['sSchoolName'],data['rows'][0]['iSchoolId']);
    };
    DataGrid.onClickRow = function (rowIndex, rowData) {
        setUrl(rowData['sSchoolNname'],rowData['iSchoolId']);
    };
    searchSch.click(function () {
        schoolList.addDataGridParams(getParams());
    });

    $('#bt_SchoolList_Time').click(function () {
        key = xhExtra.getValue($('#SchoolList_Search'));
        window.top.xhTop.showModal({
            title: '高级查询',
            content: '<iframe src="'+baseUrl+'Tch/moreSearch?schArea='+schArea+'&schCity='+schCity+'&key='+escape(key)+'"  style="width: 100%;;border-style: none;padding: 0px;height:120px"  scrolling="yes"   ></iframe>',
            size: 'md',
            button:'提交',
        });
    });


});

function getParams() {
    key = xhExtra.getValue($('#SchoolList_Search'));
    return {key:key,schArea:schArea,schCity:schCity};
}

function setUrl(schoolName,schoolId) {
    var type =xhTool.getQuery('type');
    if(type==undefined){
        $('[name=brush_english]').attr('src','https://data.yunzuoye.net/data/status_student_app.php?app=yystw&flag=12&operate=st&school='+schoolName+'&schoolid='+schoolId);
        $('[name=brush_science]').attr('src','https://data.yunzuoye.net/data/sxst_st_stat.php?flag=13&type=2&school='+schoolName+'&schoolid='+schoolId);
        $('[name=brush_math]').attr('src','https://data.yunzuoye.net/data/sxst_st_stat.php?flag=11&type=2&school='+schoolName+'&schoolid='+schoolId);
        $('[name=brush_chinese]').attr('src',baseUrl+'Stats_brush/chineseBrush?school='+schoolName+'&schoolid='+schoolId);
        $('[name=brush_mw]').attr('src','https://data.yunzuoye.net/data/status_student_app.php?app=mw&flag=10&school='+schoolName+'&schoolid='+schoolId+'&operate=st');
        $('[name=brush_tl]').attr('src','https://data.yunzuoye.net/data/status_student_app.php?app=tl&flag=4&school='+schoolName+'&schoolid='+schoolId+'&operate=st');
        $('[name=brush_pdc]').attr('src','https://data.yunzuoye.net/data/status_student_app.php?app=pdc&flag=6&school='+schoolName+'&schoolid='+schoolId+'&operate=st');
        $('[name=brush_xhz]').attr('src','https://data.yunzuoye.net/data/status_student_app.php?app=xhz&flag=5&school='+schoolName+'&schoolid='+schoolId+'&operate=st');
        $("[href='#brush_english']").click();
    }else {
        $('[name=brush_science]').attr('src','https://data.yunzuoye.net/data/sx_kx_dttj.php?flag=13&schoolid='+schoolId);
        $('[name=brush_math]').attr('src','https://data.yunzuoye.net/data/sx_kx_dttj.php?flag=11&schoolid='+schoolId);
        $("[href='#brush_math']").click();
    }

}